package proyecto.ort.edu.uy.dao.impl;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import proyecto.ort.edu.uy.dao.NivelDAOInterface;
import proyecto.ort.edu.uy.dominio.Nivel;

@Stateless
public class NivelDAOImpl implements NivelDAOInterface{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4165934471322829221L;

	@PersistenceContext(unitName = "PrototipoEM")
	private EntityManager em;
	
	@Override
	public void agregarNivel(Nivel nivel) {
		this.em.persist(nivel);
		
	}

	@Override
	public void actualizarNivel(Nivel nivel) {
		this.em.merge(nivel);
		
	}

	@Override
	public List<Nivel> buscarTodas() {
		String sql = "Select n From Nivel n";
		Query query = this.em.createQuery(sql);
		List<Nivel> lstNiveles = query.getResultList();
		// TODO Auto-generated method stub
		return lstNiveles;
	}

	@Override
	public Nivel buscarNivelPorId(Long idNivel) {
		String sql = "Select n From Nivel n Where idNivel=:idNivel";
		Query query = this.em.createQuery(sql);
		query.setParameter("idNivel", idNivel);		
		// TODO Auto-generated method stub
		return (Nivel) query.getSingleResult();
	}

}
